package com.example.day2.busi.home;

import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.example.day2.R;
import com.example.day2.adapter.FragmentAdapter;
import com.example.day2.busi.goods.ShopFragment;
import com.example.day2.databinding.FragmentHomeBinding;
import com.example.day2.entity.MyTab;
import com.example.day2.mvvm.base.BaseViewFragment;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;

public class HomeFragment extends BaseViewFragment<FragmentHomeBinding> {

    @Override
    public void initView() {
        ArrayList<CustomTabEntity> list = new ArrayList<>();
        list.add(new MyTab("发现"));
        list.add(new MyTab("推荐"));
        list.add(new MyTab("商城"));
        binding.ctl.setTabData(list);

        ArrayList<Fragment> list1 = new ArrayList<>();
        list1.add(new BlankFragment());
        list1.add(new RecommendFragment());
        list1.add(new ShopFragment());
        FragmentAdapter fragmentAdapter = new FragmentAdapter(getActivity(), list1);
        binding.vp2.setAdapter(fragmentAdapter);

        binding.vp2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                binding.ctl.setCurrentTab(position);
            }
        });

        binding.ctl.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                binding.vp2.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
    }

    @Override
    public void initData() {

    }

    @Override
    public int bindLayoutId() {
        return R.layout.fragment_home;
    }
}
